<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="inspect-source.html" />
<link rel="prev" href="module-inspect.html" />
<link rel="parent" href="module-inspect.html" />
<link rel="next" href="inspect-source.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>26.10.1 Types and members </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="26.10 inspect  "
  href="module-inspect.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="26.10 inspect  "
  href="module-inspect.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="26.10.2 retrieving source code"
  href="inspect-source.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-inspect.html">26.10 inspect  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-inspect.html">26.10 inspect  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="inspect-source.html">26.10.2 Retrieving source code</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION00281010000000000000000"></a><a name="inspect-types"></a>
<br>
26.10.1 Types and members
            
</h2>

<p>
The <tt class="function">getmembers()</tt> function retrieves the members
of an object such as a class or module.
The eleven functions whose names begin with ``is'' are mainly
provided as convenient choices for the second argument to
<tt class="function">getmembers()</tt>.  They also help you determine when
you can expect to find the following special attributes:

<p>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="center">Type</th>
      <th class="left"  >Attribute</th>
      <th class="left"  >Description</th>
      <th class="center">Notes</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="center" valign="baseline">module</td>
        <td class="left"  >__doc__</td>
        <td class="left"  >documentation string</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >__file__</td>
        <td class="left"  >filename (missing for built-in modules)</td>
        <td class="center"></td></tr>
  
    <tr><td class="center" valign="baseline">class</td>
        <td class="left"  >__doc__</td>
        <td class="left"  >documentation string</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >__module__</td>
        <td class="left"  >name of module in which this class was defined</td>
        <td class="center"></td></tr>
  
    <tr><td class="center" valign="baseline">method</td>
        <td class="left"  >__doc__</td>
        <td class="left"  >documentation string</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >__name__</td>
        <td class="left"  >name with which this method was defined</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >im_class</td>
        <td class="left"  >class object that asked for this method</td>
        <td class="center">(1)</td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >im_func</td>
        <td class="left"  >function object containing implementation of method</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >im_self</td>
        <td class="left"  >instance to which this method is bound, or <code>None</code></td>
        <td class="center"></td></tr>
  
    <tr><td class="center" valign="baseline">function</td>
        <td class="left"  >__doc__</td>
        <td class="left"  >documentation string</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >__name__</td>
        <td class="left"  >name with which this function was defined</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >func_code</td>
        <td class="left"  >code object containing compiled function bytecode</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >func_defaults</td>
        <td class="left"  >tuple of any default values for arguments</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >func_doc</td>
        <td class="left"  >(same as __doc__)</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >func_globals</td>
        <td class="left"  >global namespace in which this function was defined</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >func_name</td>
        <td class="left"  >(same as __name__)</td>
        <td class="center"></td></tr>
  
    <tr><td class="center" valign="baseline">traceback</td>
        <td class="left"  >tb_frame</td>
        <td class="left"  >frame object at this level</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >tb_lasti</td>
        <td class="left"  >index of last attempted instruction in bytecode</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >tb_lineno</td>
        <td class="left"  >current line number in Python source code</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >tb_next</td>
        <td class="left"  >next inner traceback object (called by this level)</td>
        <td class="center"></td></tr>
  
    <tr><td class="center" valign="baseline">frame</td>
        <td class="left"  >f_back</td>
        <td class="left"  >next outer frame object (this frame's caller)</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_builtins</td>
        <td class="left"  >built-in namespace seen by this frame</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_code</td>
        <td class="left"  >code object being executed in this frame</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_exc_traceback</td>
        <td class="left"  >traceback if raised in this frame, or <code>None</code></td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_exc_type</td>
        <td class="left"  >exception type if raised in this frame, or <code>None</code></td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_exc_value</td>
        <td class="left"  >exception value if raised in this frame, or <code>None</code></td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_globals</td>
        <td class="left"  >global namespace seen by this frame</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_lasti</td>
        <td class="left"  >index of last attempted instruction in bytecode</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_lineno</td>
        <td class="left"  >current line number in Python source code</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_locals</td>
        <td class="left"  >local namespace seen by this frame</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_restricted</td>
        <td class="left"  >0 or 1 if frame is in restricted execution mode</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >f_trace</td>
        <td class="left"  >tracing function for this frame, or <code>None</code></td>
        <td class="center"></td></tr>
  
    <tr><td class="center" valign="baseline">code</td>
        <td class="left"  >co_argcount</td>
        <td class="left"  >number of arguments (not including * or ** args)</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_code</td>
        <td class="left"  >string of raw compiled bytecode</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_consts</td>
        <td class="left"  >tuple of constants used in the bytecode</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_filename</td>
        <td class="left"  >name of file in which this code object was created</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_firstlineno</td>
        <td class="left"  >number of first line in Python source code</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_flags</td>
        <td class="left"  >bitmap: 1=optimized <code>|</code> 2=newlocals <code>|</code> 4=*arg <code>|</code> 8=**arg</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_lnotab</td>
        <td class="left"  >encoded mapping of line numbers to bytecode indices</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_name</td>
        <td class="left"  >name with which this code object was defined</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_names</td>
        <td class="left"  >tuple of names of local variables</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_nlocals</td>
        <td class="left"  >number of local variables</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_stacksize</td>
        <td class="left"  >virtual machine stack space required</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >co_varnames</td>
        <td class="left"  >tuple of names of arguments and local variables</td>
        <td class="center"></td></tr>
  
    <tr><td class="center" valign="baseline">builtin</td>
        <td class="left"  >__doc__</td>
        <td class="left"  >documentation string</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >__name__</td>
        <td class="left"  >original name of this function or method</td>
        <td class="center"></td></tr>
    <tr><td class="center" valign="baseline"></td>
        <td class="left"  >__self__</td>
        <td class="left"  >instance to which a method is bound, or <code>None</code></td>
        <td class="center"></td></tr></tbody>
</table></div>

<p>
Note:
<dl>
<dt><strong>(1)</strong></dt>
<dd>
<span class="versionnote">Changed in version 2.2:
<tt class="member">im_class</tt> used to refer to the class that
                defined the method.</span>

</dd>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5258' xml:id='l2h-5258' class="function">getmembers</tt></b>(</nobr></td>
  <td><var>object</var><big>[</big><var>, predicate</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return all the members of an object in a list of (name, value) pairs
  sorted by name.  If the optional <var>predicate</var> argument is supplied,
  only members for which the predicate returns a true value are included.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5259' xml:id='l2h-5259' class="function">getmoduleinfo</tt></b>(</nobr></td>
  <td><var>path</var>)</td></tr></table></dt>
<dd>
  Return a tuple of values that describe how Python will interpret the
  file identified by <var>path</var> if it is a module, or <code>None</code> if
  it would not be identified as a module.  The return tuple is
  <code>(<var>name</var>, <var>suffix</var>, <var>mode</var>, <var>mtype</var>)</code>, where
  <var>name</var> is the name of the module without the name of any
  enclosing package, <var>suffix</var> is the trailing part of the file
  name (which may not be a dot-delimited extension), <var>mode</var> is the
  <tt class="function">open()</tt> mode that would be used (<code>'r'</code> or
  <code>'rb'</code>), and <var>mtype</var> is an integer giving the type of the
  module.  <var>mtype</var> will have a value which can be compared to the
  constants defined in the <tt class="module"><a href="module-imp.html">imp</a></tt> module; see the
  documentation for that module for more information on module types.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5260' xml:id='l2h-5260' class="function">getmodulename</tt></b>(</nobr></td>
  <td><var>path</var>)</td></tr></table></dt>
<dd>
  Return the name of the module named by the file <var>path</var>, without
  including the names of enclosing packages.  This uses the same
  algorithm as the interpreter uses when searching for modules.  If
  the name cannot be matched according to the interpreter's rules,
  <code>None</code> is returned.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5261' xml:id='l2h-5261' class="function">ismodule</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a module.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5262' xml:id='l2h-5262' class="function">isclass</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a class.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5263' xml:id='l2h-5263' class="function">ismethod</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a method.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5264' xml:id='l2h-5264' class="function">isfunction</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a Python function or unnamed (lambda) function.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5265' xml:id='l2h-5265' class="function">istraceback</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a traceback.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5266' xml:id='l2h-5266' class="function">isframe</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a frame.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5267' xml:id='l2h-5267' class="function">iscode</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a code.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5268' xml:id='l2h-5268' class="function">isbuiltin</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a built-in function.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5269' xml:id='l2h-5269' class="function">isroutine</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a user-defined or built-in function or method.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5270' xml:id='l2h-5270' class="function">ismethoddescriptor</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a method descriptor, but not if ismethod() or 
  isclass() or isfunction() are true.

<p>
This is new as of Python 2.2, and, for example, is true of int.__add__.
  An object passing this test has a __get__ attribute but not a __set__
  attribute, but beyond that the set of attributes varies.  __name__ is
  usually sensible, and __doc__ often is.

<p>
Methods implemented via descriptors that also pass one of the other
  tests return false from the ismethoddescriptor() test, simply because
  the other tests promise more - you can, e.g., count on having the
  im_func attribute (etc) when an object passes ismethod().
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5271' xml:id='l2h-5271' class="function">isdatadescriptor</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a data descriptor.

<p>
Data descriptors have both a __get__ and a __set__ attribute.  Examples are
  properties (defined in Python), getsets, and members.  The latter two are
  defined in C and there are more specific tests available for those types,
  which is robust across Python implementations.  Typically, data descriptors
  will also have __name__ and __doc__ attributes (properties, getsets, and
  members have both of these attributes), but this is not guaranteed.

<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5272' xml:id='l2h-5272' class="function">isgetsetdescriptor</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a getset descriptor.

<p>
getsets are attributes defined in extension modules via <code>PyGetSetDef</code>
  structures.  For Python implementations without such types, this method will
  always return <code>False</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5273' xml:id='l2h-5273' class="function">ismemberdescriptor</tt></b>(</nobr></td>
  <td><var>object</var>)</td></tr></table></dt>
<dd>
  Return true if the object is a member descriptor.

<p>
Member descriptors are attributes defined in extension modules via
  <code>PyMemberDef</code> structures.  For Python implementations without such
  types, this method will always return <code>False</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="26.10 inspect  "
  href="module-inspect.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="26.10 inspect  "
  href="module-inspect.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="26.10.2 retrieving source code"
  href="inspect-source.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-inspect.html">26.10 inspect  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-inspect.html">26.10 inspect  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="inspect-source.html">26.10.2 Retrieving source code</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
